#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
 
long long read() {
    long long res=0, w=1; char c=getchar();
    while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
    while(isdigit(c)) {res=res*10+c-48, c=getchar();}
    return res*w;
}

const int N=2e5+9;
int n,s[N],t[N],ans;
struct node {int a,b;} x[N];
bool cmp(const node &a,const node &b) {return a.b>b.b;}

signed main() {
    freopen("boast.in","r",stdin);
    freopen("boast.out","w",stdout);
    n=read();
    rep(i,1,n) x[i].a=read(), x[i].b=read();
    sort(x+1,x+n+1,cmp);
    s[0]=t[n+1]=ans=0x3f3f3f3f;
    rep(i,1,n) s[i]=min(s[i-1],x[i].a+x[i].b);
    per(i,n,1) t[i]=min(t[i+1],x[i].a);
    rep(i,1,n) ans=min(ans,s[i-1]+t[i+1]+x[i].a+x[i].b);
    printf("%lld\n",ans);
    return 0;
}